package com.four.basicinfo.controller;

import com.four.basicinfo.code.ResponseData;
import com.four.basicinfo.dao.InformationDao;
import com.four.basicinfo.entity.Information;
import com.four.basicinfo.service.InformationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/information")
@CrossOrigin
public class InformationController extends BaseController{
    @Autowired
    InformationDao informationDao;
    @Autowired
    InformationService informationService;

    /**
     * 获取基本信息详细信息
     */
    @GetMapping("/selectById")
    public Information getInfo(Long id)
    {
        Information information=informationService.selectInformationById(id);
        return information;
    }

    //查看
    @GetMapping("/select")
    public ResponseData<Object> getPeople(
            @RequestParam("pageNum") int pageNum,
            @RequestParam("pageSize") int pageSize,
            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "number",required = false) Integer number,
            @RequestParam(value = "sex",required = false) String sex,
            @RequestParam(value = "employee",required = false) String employee,
            @RequestParam(value = "grade",required = false) String grade,
            @RequestParam(value = "duties",required = false) String duties,
            @RequestParam(value = "education",required = false) String education,
            @RequestParam(value = "marriage",required = false) String marriage
    ){
        return returnObject(informationService.getOnrePage(pageNum,pageSize,name,number, sex, employee, grade, duties, education, marriage));
    }
    /**
     * 查询本人的信息
     */
    @GetMapping("/listBynum")
    public Information list(String number){
        Information list = informationDao.selectByNum(number);
        return list;
    }

    /**
     * 查询本人的学历
     */
    @GetMapping("/edulist")
    public List<Information> eduList(String number){
        List<Information> list = informationDao.selectEdu(number);
        return list;
    }

    /**
     * 修改基本信息
     */

    @PutMapping("/update")
    public ResponseData<Boolean> update(Information information){
        Boolean b = informationService.updateInformation( information );
        return returnBoolean( b );
    }


}
